<template>
    <div class="main-con messageManagement">
        <!-- 搜索框 -->
        <div class="search-con">
            <div class="search-item">
                <div class="search-item-title">消息标题</div>
                <div class="search-item-input">
                    <el-input size="mini" v-model="formData.msgTitle" placeholder="请输入消息标题" @change="handleSearch"></el-input>
                </div>
            </div>
            <div class="search-item">
                <div class="search-item-title">发布时间</div>
                <div class="search-item-input">
                    <el-date-picker size="mini" :editable="false" class="w200" v-model="formData.beginTime" type="date"
                        placeholder="请选择开始时间" value-format="yyyy-MM-dd" :clearable="false"></el-date-picker>
                </div>
                <div>~</div>
                <div class="search-item-input">
                    <el-date-picker size="mini" :editable="false" class="w200" v-model="formData.endTime" type="date"
                        placeholder="请选择结束时间" value-format="yyyy-MM-dd" :clearable="false"></el-date-picker>
                </div>
            </div>
            <div class="search-item">
                <div class="search-item-title"></div>
                <el-button size="mini" type="primary" icon="el-icon-search" @click="handleSearch">查询</el-button>
                <el-button size="mini" type="primary" icon="el-icon-delete" @click="handleClear">清空</el-button>
            </div>
        </div>

        <!-- 按钮组 -->
        <div class="btn-group-con">
            <el-button size="mini" type="primary" @click="handleAdd">添加</el-button>
            <el-button size="mini" type="primary" @click="handleDelete">删除</el-button>
        </div>

        <!-- 表格数据 -->
        <div class="table-con" v-loading="loading">
            <el-table :data="tableData" size="mini" :header-cell-style="{background:'#f8f8f8'}" style="width: 100%"
                @selection-change="handleSelectionChange">
                <el-table-column type="selection" align="center" width="50">
                </el-table-column>
                <el-table-column type="index" label="序号" width="50" align="center" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column prop="msgTitle" label="消息标题" width="" align="center" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column prop="msgContent" label="消息内容" width="" align="center" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column prop="msgType" label="推送类型" width="" align="center" :show-overflow-tooltip="true">
                    <template slot-scope="scope">
                        <span v-if="scope.row.msgType == 0">正常订单</span>
                        <span v-if="scope.row.msgType == 1">紧急订单</span>
                    </template>
                </el-table-column>
                <el-table-column prop="createTime" label="发布时间" width="140" align="center" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column prop="" label="推送对象" width="100" align="center" :show-overflow-tooltip="true">
                    <template slot-scope="scope">
                        <span v-if=" scope.row.id">骑手</span>
                    </template>
                </el-table-column>
                <el-table-column label="操作" width="120" align="center">
                    <template slot-scope="scope">
                        <div class="handleBtn">
                            <span @click="handleUpdate(scope.$index, scope.row)">编辑</span>
                            <span @click="handleDelete(scope.$index, scope.row)">删除</span>
                        </div>
                    </template>
                </el-table-column>
            </el-table>
        </div>

        <!-- 表格分页 -->
        <div class="pagination-con">
            <m-pagination :currentPage="formData.pageNum" :pageSize="formData.pageSize" :total="total"
                @handleCurrentChange="handleCurrentChange" @handleSizeChange="handleSizeChange">
            </m-pagination>
        </div>
    </div>
</template>

<script>
import { queryMessageManagementInfo } from "@/common/service/systemManagement/messageManagement.js";
import mPagination from "@/components/m-pagination/m-pagination";
export default {
    name: "messageManagement",
    data() {
        return {
            // 搜索条件
            formData: {
                msgTitle: "", //消息标题
                beginTime: "", //发布开始时间
                endTime: "", //发布结束时间
                pageNum: 1,
                pageSize: 10
            },
            //表格数据
            tableData: [], //表格信息
            total: null, //表格总条数
            loading: false //表格加载动画
        };
    },
    created() {
        //初始化表格数据
        this._queryMessageManagementInfo();
    },
    methods: {
        /*----------------------------查询操作----------------------------*/
        //查询消息推送信息表格数据
        _queryMessageManagementInfo() {
            this.loading = true;
            queryMessageManagementInfo(this.formData)
                .then(res => {
                    this.loading = false;
                    this.tableData = res.content;
                    this.total = res.totalElements;
                })
                .catch(err => {
                    this.loading = false;
                    this.$message.error(err.message);
                });
        },
        //页码切换
        handleCurrentChange(val) {
            this.formData.pageNum = val;
            this._queryMessageManagementInfo();
        },
        //每页展示条数的切换
        handleSizeChange(val) {
            this.formData.pageSize = val;
            this._queryMessageManagementInfo();
        },
        //点击查询
        handleSearch() {
            this.formData.pageNum = 1;
            this.formData.pageSize = 10;
            this._queryMessageManagementInfo();
        },
        //点击清空
        handleClear() {
            this.formData = {
                userName: "",
                sources: "",
                moudleCode: "",
                remark: "",
                storeName: "",
                start: "",
                end: "",
                pageNum: 1,
                pageSize: 10
            };
            this.$message({
                type: "success",
                message: "清空成功!"
            });
            this._queryMessageManagementInfo();
        },

        /*----------------------------添加操作----------------------------*/
        handleAdd() {
            this.$router.push({
                path: "/index/messageManagement/editMessageManagement",
                query: {
                    editType: "add",
                    editText: "新增"
                }
            });
        },

        /*----------------------------编辑操作----------------------------*/
        handleUpdate(index, row) {
            this.$router.push({
                path: "/index/messageManagement/editMessageManagement",
                query: {
                    editType: "update",
                    editText: "编辑"
                }
            });
            localStorage.setItem("editData", JSON.stringify(row));
        },

        /*----------------------------删除操作----------------------------*/
        //点击删除
        handleDelete(index, row) {
            this.$confirm("您确定删除此系统用户吗？", "删除系统用户信息", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
            })
                .then(() => {
                    this._deleteSystemUserInfo(row);
                })
                .catch(() => {
                    this.$message({
                        type: "info",
                        message: "已取消删除"
                    });
                });
        },
        //执行删除操作
        _deleteSystemUserInfo(row) {
            var data = {
                id: row.id
            };
            deleteSystemUserInfo(data)
                .then(res => {
                    this.$message({
                        type: "success",
                        message: "删除成功!"
                    });
                    this._querySystemUserInfo();
                })
                .catch(err => {
                    this.$message.error(err.message);
                });
        },

        /*----------------------------多选框勾选数据的操作----------------------------*/
        handleSelectionChange(val) {
            this.handleSelection = val;
        }
    },
    components: {
        "m-pagination": mPagination
    }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
</style>